﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace SMSPanasonic.Business
{
    public partial class pa_WarrantyDetail
    {
    	#region public properties
		public int WarrantyDetailID { get; set; }
		public string ModelCode { get; set; }
		public string ProductCode { get; set; }
		public int AgencyID { get; set; }
		public string CustomerPhone { get; set; }
		public int? CustomerGroupID { get; set; }
		public int? WarrantyPackageID { get; set; }
		public DateTime RegisterDate { get; set; }
		public DateTime ConfirmDate { get; set; }
		public DateTime ExpiredDate { get; set; }
		public int UserID { get; set; }
		public string WarrantyType { get; set; }
		public string Description { get; set; }
		#endregion

		#region constructor
		public pa_WarrantyDetail(){ }

		public pa_WarrantyDetail(IDataReader rd)
		{
			this.WarrantyDetailID = (int)rd["WarrantyDetailID"];
			this.ModelCode = rd["ModelCode"].ToString();
			this.ProductCode = rd["ProductCode"].ToString();
			this.AgencyID = (int)rd["AgencyID"];
			this.CustomerPhone = rd["CustomerPhone"].ToString();
			this.CustomerGroupID = rd["CustomerGroupID"].Equals(DBNull.Value) ? (int?)null : (int)rd["CustomerGroupID"];
			this.WarrantyPackageID = rd["WarrantyPackageID"].Equals(DBNull.Value) ? (int?)null : (int)rd["WarrantyPackageID"];
			this.RegisterDate = (DateTime)rd["RegisterDate"];
			this.ConfirmDate = (DateTime)rd["ConfirmDate"];
			this.ExpiredDate = (DateTime)rd["ExpiredDate"];
			this.UserID = (int)rd["UserID"];
			this.WarrantyType = rd["WarrantyType"].ToString();
			this.Description = rd["Description"].ToString();
		}
		#endregion

        #region static method
        public static DataTable GetByCustomerPhone(string customerphone)
        {
            DataTable dtRet = new DataTable();
            using (SqlDataReader rd = SqlHelper.ExecuteReader(AppConfig.ConnectionString, CommandType.StoredProcedure, "usp_WarrantyDetail_GetByPhone", 
                new SqlParameter("@Phone", customerphone))
                )
            {
                dtRet.Load(rd);
            }
            return dtRet;
        }

        public static DataTable GetByModelAndProduct(string modelcode, string productCode)
        {
            DataTable dtRet = new DataTable();
            using (SqlDataReader rd = SqlHelper.ExecuteReader(AppConfig.ConnectionString, CommandType.StoredProcedure, "[usp_WarrantyDetail_ModelAndProduct]",
                new SqlParameter("@ModelCode", modelcode), new SqlParameter("@ProductCode", productCode))
                )
            {
                dtRet.Load(rd);
            }
            return dtRet;
        }
		#endregion
	}
}
